home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / DatabaseAccess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  12.5 KB  |  369 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Contains:    Database Access Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1989-1998, 1995-1997 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __DATABASEACCESS__
  18. #define __DATABASEACCESS__
  19.  
  20. #ifndef __RESOURCES__
  21. #include <Resources.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46. /* data type codes */
  47.  
  48. enum {
  49.     typeNone                    = FOUR_CHAR_CODE('none'),
  50.     typeDate                    = FOUR_CHAR_CODE('date'),
  51.     typeTime                    = FOUR_CHAR_CODE('time'),
  52.     typeTimeStamp                = FOUR_CHAR_CODE('tims'),
  53.     typeDecimal                    = FOUR_CHAR_CODE('deci'),
  54.     typeMoney                    = FOUR_CHAR_CODE('mone'),
  55.     typeVChar                    = FOUR_CHAR_CODE('vcha'),
  56.     typeVBin                    = FOUR_CHAR_CODE('vbin'),
  57.     typeLChar                    = FOUR_CHAR_CODE('lcha'),
  58.     typeLBin                    = FOUR_CHAR_CODE('lbin'),
  59.     typeDiscard                    = FOUR_CHAR_CODE('disc'),        /* "dummy" types for DBResultsToText */
  60.     typeUnknown                    = FOUR_CHAR_CODE('unkn'),
  61.     typeColBreak                = FOUR_CHAR_CODE('colb'),
  62.     typeRowBreak                = FOUR_CHAR_CODE('rowb'),        /* pass this in to DBGetItem for any data type */
  63.     typeAnyType                    = 0
  64. };
  65.  
  66. /* infinite timeout value for DBGetItem */
  67.  
  68. enum {
  69.                                                                 /* messages for status functions for DBStartQuery */
  70.     kDBUpdateWind                = 0,
  71.     kDBAboutToInit                = 1,
  72.     kDBInitComplete                = 2,
  73.     kDBSendComplete                = 3,
  74.     kDBExecComplete                = 4,
  75.     kDBStartQueryComplete        = 5
  76. };
  77.  
  78.  
  79. enum {
  80.                                                                 /* messages for status functions for DBGetQueryResults */
  81.     kDBGetItemComplete            = 6,
  82.     kDBGetQueryResultsComplete    = 7,
  83.     kDBWaitForever                = -1
  84. };
  85.  
  86.  
  87. enum {
  88.                                                                 /*  flags for DBGetItem  */
  89.     kDBLastColFlag                = 0x0001,
  90.     kDBNullFlag                    = 0x0004
  91. };
  92.  
  93. typedef OSType                             DBType;
  94. typedef struct DBAsyncParamBlockRec     DBAsyncParamBlockRec;
  95. typedef DBAsyncParamBlockRec *            DBAsyncParmBlkPtr;
  96. typedef CALLBACK_API( void , DBCompletionProcPtr )(DBAsyncParmBlkPtr pb);
  97. /*
  98.     WARNING: DBCompletionProcPtr uses register based parameters under classic 68k
  99.              and cannot be written in a high-level language without 
  100.              the help of mixed mode or assembly glue.
  101. */
  102. typedef REGISTER_UPP_TYPE(DBCompletionProcPtr)                     DBCompletionUPP;
  103. /* structure for asynchronous parameter block */
  104.  
  105. struct DBAsyncParamBlockRec {
  106.     DBCompletionUPP                 completionProc;                /* pointer to completion routine */
  107.     OSErr                             result;                        /* result of call */
  108.     long                             userRef;                    /* for application's use */
  109.     long                             ddevRef;                    /* for ddev's use */
  110.     long                             reserved;                    /* for internal use */
  111. };
  112.  
  113. /* structure for resource list in QueryRecord */
  114.  
  115. struct ResListElem {
  116.     ResType                         theType;                    /* resource type */
  117.     short                             id;                            /* resource id */
  118. };
  119. typedef struct ResListElem                ResListElem;
  120.  
  121. typedef ResListElem *                    ResListPtr;
  122. typedef ResListPtr *                    ResListHandle;
  123. /* structure for query list in QueryRecord */
  124. typedef Handle                             QueryArray[256];
  125. typedef Handle *                        QueryListPtr;
  126. typedef QueryListPtr *                    QueryListHandle;
  127.  
  128. struct QueryRecord {
  129.     short                             version;                    /* version */
  130.     short                             id;                            /* id of 'qrsc' this came from */
  131.     Handle                             queryProc;                    /* handle to query def proc */
  132.     Str63                             ddevName;                    /* ddev name */
  133.     Str255                             host;                        /* host name */
  134.     Str255                             user;                        /* user name */
  135.     Str255                             password;                    /* password */
  136.     Str255                             connStr;                    /* connection string */
  137.     short                             currQuery;                    /* index of current query */
  138.     short                             numQueries;                    /* number of queries in list */
  139.     QueryListHandle                 queryList;                    /* handle to array of handles to text */
  140.     short                             numRes;                        /* number of resources in list */
  141.     ResListHandle                     resList;                    /* handle to array of resource list elements */
  142.     Handle                             dataHandle;                    /* for use by query def proc */
  143.     long                             refCon;                        /* for use by application */
  144. };
  145. typedef struct QueryRecord                QueryRecord;
  146.  
  147. typedef QueryRecord *                    QueryPtr;
  148. typedef QueryPtr *                        QueryHandle;
  149. /* structure of column types array in ResultsRecord */
  150. typedef DBType                             ColTypesArray[256];
  151. typedef Handle                             ColTypesHandle;
  152. /* structure for column info in ResultsRecord */
  153.  
  154. struct DBColInfoRecord {
  155.     short                             len;
  156.     short                             places;
  157.     short                             flags;
  158. };
  159. typedef struct DBColInfoRecord            DBColInfoRecord;
  160.  
  161. typedef DBColInfoRecord                 ColInfoArray[256];
  162. typedef Handle                             ColInfoHandle;
  163. /* structure of results returned by DBGetResults */
  164.  
  165. struct ResultsRecord {
  166.     short                             numRows;                    /* number of rows in result */
  167.     short                             numCols;                    /* number of columns per row */
  168.     ColTypesHandle                     colTypes;                    /* data type array */
  169.     Handle                             colData;                    /* actual results */
  170.     ColInfoHandle                     colInfo;                    /* DBColInfoRecord array */
  171. };
  172. typedef struct ResultsRecord            ResultsRecord;
  173.  
  174. enum {
  175.                                                                 /* messages sent to a 'ddev'*/
  176.     kDBInit                        = 0,
  177.     kDBEnd                        = 1,
  178.     kDBGetConnInfo                = 2,
  179.     kDBGetSessionNum            = 3,
  180.     kDBSend                        = 4,
  181.     kDBSendItem                    = 5,
  182.     kDBExec                        = 6,
  183.     kDBState                    = 7,
  184.     kDBGetErr                    = 8,
  185.     kDBBreak                    = 9,
  186.     kDBGetItem                    = 10,
  187.     kDBUngetItem                = 11,
  188.     kDBKill                        = 12,
  189.     kDBOpen                        = 100,
  190.     kDBClose                    = 101,
  191.     kDBIdle                        = 102
  192. };
  193.  
  194. typedef CALLBACK_API( OSErr , DBQueryDefProcPtr )(long *sessID, QueryHandle query);
  195. typedef CALLBACK_API( Boolean , DBStatusProcPtr )(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  196. typedef CALLBACK_API( OSErr , DBResultHandlerProcPtr )(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  197. typedef STACK_UPP_TYPE(DBQueryDefProcPtr)                         DBQueryDefUPP;
  198. typedef STACK_UPP_TYPE(DBStatusProcPtr)                         DBStatusUPP;
  199. typedef STACK_UPP_TYPE(DBResultHandlerProcPtr)                     DBResultHandlerUPP;
  200. enum { uppDBCompletionProcInfo = 0x0000B802 };                     /* register no_return_value Func(4_bytes:A1) */
  201. enum { uppDBQueryDefProcInfo = 0x000003E0 };                     /* pascal 2_bytes Func(4_bytes, 4_bytes) */
  202. enum { uppDBStatusProcInfo = 0x000FAA90 };                         /* pascal 1_byte Func(2_bytes, 2_bytes, 2_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes) */
  203. enum { uppDBResultHandlerProcInfo = 0x0003EAE0 };                 /* pascal 2_bytes Func(4_bytes, 2_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes) */
  204. #define NewDBCompletionProc(userRoutine)                         (DBCompletionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  205. #define NewDBQueryDefProc(userRoutine)                             (DBQueryDefUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  206. #define NewDBStatusProc(userRoutine)                             (DBStatusUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  207. #define NewDBResultHandlerProc(userRoutine)                     (DBResultHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  208. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  209.     #pragma parameter CallDBCompletionProc(__A0, __A1)
  210.     void CallDBCompletionProc(DBCompletionUPP routine, DBAsyncParmBlkPtr pb) = 0x4E90;
  211. #else
  212.     #define CallDBCompletionProc(userRoutine, pb)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppDBCompletionProcInfo, (pb))
  213. #endif
  214. #define CallDBQueryDefProc(userRoutine, sessID, query)             CALL_TWO_PARAMETER_UPP((userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  215. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)  CALL_SEVEN_PARAMETER_UPP((userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  216. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)  CALL_SIX_PARAMETER_UPP((userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  217. EXTERN_API( OSErr )
  218. InitDBPack                        (void)                                                        FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  219.  
  220. EXTERN_API( OSErr )
  221. DBInit                            (long *                    sessID,
  222.                                  ConstStr63Param         ddevName,
  223.                                  ConstStr255Param         host,
  224.                                  ConstStr255Param         user,
  225.                                  ConstStr255Param         passwd,
  226.                                  ConstStr255Param         connStr,
  227.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  228.  
  229. EXTERN_API( OSErr )
  230. DBEnd                            (long                     sessID,
  231.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  232.  
  233. EXTERN_API( OSErr )
  234. DBGetConnInfo                    (long                     sessID,
  235.                                  short                     sessNum,
  236.                                  long *                    returnedID,
  237.                                  long *                    version,
  238.                                  Str63                     ddevName,
  239.                                  Str255                 host,
  240.                                  Str255                 user,
  241.                                  Str255                 network,
  242.                                  Str255                 connStr,
  243.                                  long *                    start,
  244.                                  OSErr *                state,
  245.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  246.  
  247. EXTERN_API( OSErr )
  248. DBGetSessionNum                    (long                     sessID,
  249.                                  short *                sessNum,
  250.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  251.  
  252. EXTERN_API( OSErr )
  253. DBSend                            (long                     sessID,
  254.                                  Ptr                     text,
  255.                                  short                     len,
  256.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  257.  
  258. EXTERN_API( OSErr )
  259. DBSendItem                        (long                     sessID,
  260.                                  DBType                 dataType,
  261.                                  short                     len,
  262.                                  short                     places,
  263.                                  short                     flags,
  264.                                  void *                    buffer,
  265.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  266.  
  267. EXTERN_API( OSErr )
  268. DBExec                            (long                     sessID,
  269.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  270.  
  271. EXTERN_API( OSErr )
  272. DBState                            (long                     sessID,
  273.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  274.  
  275. EXTERN_API( OSErr )
  276. DBGetErr                        (long                     sessID,
  277.                                  long *                    err1,
  278.                                  long *                    err2,
  279.                                  Str255                 item1,
  280.                                  Str255                 item2,
  281.                                  Str255                 errorMsg,
  282.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  283.  
  284. EXTERN_API( OSErr )
  285. DBBreak                            (long                     sessID,
  286.                                  Boolean                 abort,
  287.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  288.  
  289. EXTERN_API( OSErr )
  290. DBGetItem                        (long                     sessID,
  291.                                  long                     timeout,
  292.                                  DBType *                dataType,
  293.                                  short *                len,
  294.                                  short *                places,
  295.                                  short *                flags,
  296.                                  void *                    buffer,
  297.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  298.  
  299. EXTERN_API( OSErr )
  300. DBUnGetItem                        (long                     sessID,
  301.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  302.  
  303. EXTERN_API( OSErr )
  304. DBKill                            (DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  305.  
  306. EXTERN_API( OSErr )
  307. DBGetNewQuery                    (short                     queryID,
  308.                                  QueryHandle *            query)                                THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  309.  
  310. EXTERN_API( OSErr )
  311. DBDisposeQuery                    (QueryHandle             query)                                THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  312.  
  313. EXTERN_API( OSErr )
  314. DBStartQuery                    (long *                    sessID,
  315.                                  QueryHandle             query,
  316.                                  DBStatusUPP             statusProc,
  317.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  318.  
  319. EXTERN_API( OSErr )
  320. DBGetQueryResults                (long                     sessID,
  321.                                  ResultsRecord *        results,
  322.                                  long                     timeout,
  323.                                  DBStatusUPP             statusProc,
  324.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  325.  
  326. EXTERN_API( OSErr )
  327. DBResultsToText                    (ResultsRecord *        results,
  328.                                  Handle *                theText)                            THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  329.  
  330. EXTERN_API( OSErr )
  331. DBInstallResultHandler            (DBType                 dataType,
  332.                                  DBResultHandlerUPP     theHandler,
  333.                                  Boolean                 isSysHandler)                        THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  334.  
  335. EXTERN_API( OSErr )
  336. DBRemoveResultHandler            (DBType                 dataType)                            THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  337.  
  338. EXTERN_API( OSErr )
  339. DBGetResultHandler                (DBType                 dataType,
  340.                                  DBResultHandlerUPP *    theHandler,
  341.                                  Boolean                 getSysHandler)                        THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  342.  
  343. EXTERN_API( OSErr )
  344. DBIdle                            (void)                                                        THREEWORDINLINE(0x303C, 0x00FF, 0xA82F);
  345.  
  346.  
  347.  
  348.  
  349. #if PRAGMA_STRUCT_ALIGN
  350.     #pragma options align=reset
  351. #elif PRAGMA_STRUCT_PACKPUSH
  352.     #pragma pack(pop)
  353. #elif PRAGMA_STRUCT_PACK
  354.     #pragma pack()
  355. #endif
  356.  
  357. #ifdef PRAGMA_IMPORT_OFF
  358. #pragma import off
  359. #elif PRAGMA_IMPORT
  360. #pragma import reset
  361. #endif
  362.  
  363. #ifdef __cplusplus
  364. }
  365. #endif
  366.  
  367. #endif /* __DATABASEACCESS__ */
  368.  
  369.